package com.csw.scala
import scala.collection.mutable
import scala.collection.mutable.HashSet
object Demo16Set {
  def main(args: Array[String]): Unit = {

    /**
      * set: 无序唯一
      */

    val set = Set(5,6,6,10,15,20,25,7,8)
    println(set)

    println(set.max)
    println(set.min)
    println(set.sum)
    println(set.mkString(","))
    println(set.filter((i: Int) => i>10))
    println(set.map(i => i+50))



    val set1 = Set(1,2,3,4,5,6,7)
    val set2 = Set(3,4,5,6,7,8,9,10)

    //交集
    println(set1.&(set2))
    //并集
    println(set1 | set2)
    //差集
    println(set2 &~ set1)


    /**
      * 可变set
      */
    val hashSet = new mutable.HashSet[Int]()

    hashSet.add(500)

    hashSet += 300

    println(hashSet)

    //清空
    hashSet.clear()

    println(hashSet)
  }

}
